package mrdemo007;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
 
public class Test1 {
	/**
	 *  topN问题
	 *  orderid,userid,payment,productid
	 *  订单id，用户id，付款金额，商品id
	 *  1,9873,100,1020
		2,9871,1100,2020
		3,9873,200,320
		4,1873,1200,520
		5,3873,160,1820
		6,9233,180,1920
		7,9673,1890,103
		8,9173,900,104
		9,1173,800,1025
		10,1873,900,1070
		11,2823,10,1024
		12,3813,155,120
	 * 求所有数据中，付款金额最大的top5的订单金额，要求输出：
	 * 
	 * 	1	1890
		2	1200
		3	1100
		4	900
		5	900
	 */

	public static void main(String[] args) throws Exception {

		Configuration conf = new Configuration(); // 加载配置文件
		conf.set("N", "5");
		Job job = new Job(conf); // 创建一个job，供JobTracker使用
//		job.setJarByClass(Test1.class);

		job.setMapperClass(TopNMap.class);
		job.setReducerClass(TopNReduce.class);

//		FileInputFormat.setInputPaths(job, new Path("hdfs://192.168.52.100:8020/topNInput"));
//		FileOutputFormat.setOutputPath(job, new Path("hdfs://192.168.52.100:8020/topNOutput"));
		
		FileInputFormat.setInputPaths(job, new Path("c:/data/topNInput"));
		FileOutputFormat.setOutputPath(job, new Path("c:/data/topNOutput"));
		
		
		//map的输出数据的类型
		job.setOutputKeyClass(IntWritable.class);
		job.setOutputValueClass(IntWritable.class);

		job.waitForCompletion(true);

	}

}
